package xin.yangshuai.fastjson01.hello;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

/**
 * Main
 *
 * @author shuai
 * @date 2023/4/24
 */
public class Main {
    public static void main(String[] args) {
        User user = new User();
        user.setCompanyName("company123");
        user.setDepartmentName("department123");
        user.setPostName("post123");
        String s = JSON.toJSONString(user);
        System.out.println(s);

        JSONObject jsonObject = JSON.parseObject(s);
        System.out.println(jsonObject);

        String json = "{\"age\":0,\"companyName\":\"company123\",\"departmentName\":\"department123\",\"id\":0,\"postName\":\"post123\"}";
        String json1 = "{\"age\":0,\"company_name\":\"company123\",\"department_name\":\"department123\",\"id\":0,\"post_name\":\"post123\"}";

        // , alternateNames = {"componentKey"}

        User user1 = JSON.parseObject(json, User.class, Feature.DisableFieldSmartMatch);
        System.out.println(user1);

        User user2 = JSON.parseObject(json, User.class);
        System.out.println(user2);

        User user3 = JSON.parseObject(json1, User.class);
        System.out.println(user3);

        User user4 = jsonObject.toJavaObject(User.class);
        System.out.println(user4);
    }
}
